const getCurPage = () => {
  const pages = getCurrentPages();
  const curPage = pages[pages.length - 1];
  return curPage;
};

/**
 * 去除接口请求的时候有 undefined、null、0等数据
 *
 *
 */
const handleParmas = (params) => {
  let ObjKey = Object.keys(params);
  let _parmas = {};
  ObjKey.forEach((item) => {
    if (params[item]) {
      _parmas[item] = params[item];
    }
  });
  return _parmas;
};

/**
 * 自定义NavBar高度（使用uniapp的u-navbar）
 * @return {number}  rpx值
 */
const getNavBarHeight = () => {
  const systemInfo = uni.getSystemInfoSync();
  const _navBarHeight = systemInfo.platform == "ios" ? 44 : 48;

  return handleRpx(_navBarHeight) + handleRpx(systemInfo.statusBarHeight);
};

/** px转rpx 注意：uni.upx2px 是rpx转px
 *  value: px值
 *  @return {number} rpx值
 */
const handleRpx = (value) => {
  return value / (uni.upx2px(100) / 100);
};

export { getCurPage, handleParmas, getNavBarHeight, handleRpx };
